//
//  BaiKeSecondClassesTopView.m
//  BaseProject
//
//  Created by mac on 2020/12/22.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "BaiKeSecondClassesTopView.h"
#import "BaiKeSecondClassesPopView.h"
#import "BaiKeMainClassesModel.h"
@interface BaiKeSecondClassesTopView ()
@property(nonatomic,strong)UIImageView *bgIV;
@property(nonatomic,strong)UILabel *titleLab;
@property(nonatomic,strong)BaseAdjustButton *sortButton;
@end

@implementation BaiKeSecondClassesTopView
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = WhiteColor;
        [self bgIV];
        [self sortButton];
    }
    return self;
}
- (void)setOneName:(NSString *)oneName
{
    _oneName = oneName;
    self.titleLab.text = oneName;
}
#pragma mark - click
- (void)clickSortButton:sender
{
    BaiKeSecondClassesPopView *view = [[BaiKeSecondClassesPopView alloc]initWithFrame:CGRectMake(0, 0, self.width, 450*ADAPTER_WIDTH + kBottomSafeHeight) withParentView:self.parentVC.view];
    view.classesModel = self.classesModel;
    WK(weakSelf)
    [view setCallBackSelectedBlock:^(NSInteger secondIndex, NSInteger threeIndex) {
        !weakSelf.callBackSelectedBlock ?: weakSelf.callBackSelectedBlock (secondIndex,threeIndex);
    }];
}
#pragma mark - lazy懒加载
- (UIImageView *)bgIV
{
    if (!_bgIV) {
        UIImageView *iv = [[UIImageView alloc]init];
        [self addSubview:iv];
        iv.image = [UIImage getPNGimageInBundleWithName:@"BaiKe_top_bg"];
        iv.contentMode = UIViewContentModeScaleAspectFill;
        iv.clipsToBounds = YES;
        iv.frame = CGRectMake(0, 0, self.width, self.height);
        _bgIV = iv;
    }
    return _bgIV;
}
- (UILabel *)titleLab
{
    if (!_titleLab) {
        UILabel *lab = [[UILabel alloc]init];
        [self addSubview:lab];
        lab.font = [UIFont systemFontOfSize:20*ADAPTER_WIDTH weight:UIFontWeightBold];
        lab.textColor = WhiteColor;
        lab.textAlignment = NSTextAlignmentLeft;
        lab.numberOfLines = 1;
        lab.frame = CGRectMake(20*ADAPTER_WIDTH, 15*ADAPTER_WIDTH, self.width - 40*ADAPTER_WIDTH, 28*ADAPTER_WIDTH);
        _titleLab = lab;
    }
    return _titleLab;
}
- (BaseAdjustButton *)sortButton
{
    if (!_sortButton) {
        BaseAdjustButton *button = [BaseAdjustButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:button];
        button.type = layoutTypeHorizontalLeftTitleRightImage;
        button.title = @"筛选相关分类";
        button.fontWeight = UIFontWeightRegular;
        button.fontSize = 13*ADAPTER_WIDTH;
        button.imageWidth = 5*ADAPTER_WIDTH;
        button.imageHeight = 8*ADAPTER_WIDTH;
        button.marginLeft = 7*ADAPTER_WIDTH;
        button.marginItemX = 4*ADAPTER_WIDTH;
        button.marginRight = 6*ADAPTER_WIDTH;
        button.marginTop = 6*ADAPTER_WIDTH;
        button.marginBottom = 6*ADAPTER_WIDTH;
        [button begin];
        [button setTitleColor:rgba(255, 85, 58, 1) forState:UIControlStateNormal];
        [button setImage:[UIImage getPNGimageInBundleWithName:@"BaiKe_arrow_right"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickSortButton:) forControlEvents:UIControlEventTouchUpInside];
        button.backgroundColor = WhiteColor;
        button.layer.cornerRadius = 5*ADAPTER_WIDTH;
        button.layer.masksToBounds = YES;
        button.left = 21*ADAPTER_WIDTH;
        button.top = self.titleLab.bottom + 8*ADAPTER_WIDTH;
        _sortButton = button;
    }
    return _sortButton;
}
@end
